home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / moveto.exe / MOVETO.ASM < prev    next >
Assembly Source File  |  1992-02-23  |  2KB  |  66 lines

  1.         .PAGE    ,132
  2.         .TITLE    Move To - move a string to a character
  3. %        .MODEL    memmodel,C    ; OS/2 Function
  4.  
  5.  
  6.  
  7. ; This function moves characters from the source to the destination until the 
  8. ; terminating character, termch, is encountered in the source string or maxlen
  9. ; characters are transferred.  The terminating character is not transferred.  At
  10. ; the conclusion of the transfer, the function returns the NEXT location in the
  11. ; destination string.  A zero byte does NOT stop the transfer unless this function
  12. ; is assembled wity STOP_ON_ZERO_BYTE defined (see below)
  13.  
  14. ;In c this would be:
  15.  
  16. ;    ptr = moveto(destination, source, maximum_length, terminating char);
  17. ;    [ char destination, source ]
  18. ;    [ int maximum_length ]
  19. ;    [ char terminating character]
  20. ;No checks are made as to the validity of the string addresses.  No stack checks
  21. ;are made on entry, testing for stack overflow etc... You have been warned
  22.  
  23. ;Programmed By: A. L. Bender, M. D.
  24. ;        January 22, 1992
  25. ;        [Used in insurance form print routine]
  26. ;
  27. ; If transfer is to stop on a zero byte ('\0') then STOP_ON_ZERO_BYTE should
  28. ; be defined either by an EQU here or by a /DSTOP_ON_ZERO_BYTE on the control
  29. ; statement.
  30.         .CODE    ; This function has no data segment
  31.         .LALL
  32. movetto     PROC    USES SI DI CX ES DS, dest:PTR BYTE, source:PTR BYTE, maxlen:WORD,\
  33.             termch:BYTE
  34.         PUSHF            ; Save the flags
  35.                     ; Segment registers saved already
  36.         CLD            ; set to go forwards thru the source
  37.         IF    @DataSize    ; Compile the proper instructions
  38.         LES    DI,[dest]    ; get destination pointer
  39.         LDS    SI,[source]    ; get source pointer
  40.         ELSE            ; For the appropriate memory model
  41.         MOV    DI,[dest]    ; same but small model
  42.         MOV    SI,[source]    ;
  43.         ENDIF
  44.         MOV    CX,[maxlen]    ; get maximum length
  45.         TEST    CX,CX        ; If no characters are to be moved
  46.         JZ    @2        ; Immediately leave
  47.         MOV    AH,[termch]    ; get the terminating character
  48. @1:        LODSB            ; loop moving characters
  49.         CMP    AL,AH        ; got it yet?
  50.         JZ    @2        ; yup!
  51.         STOSB            ; no, store this character
  52.         IFDEF    STOP_ON_ZERO    ; conditional assembly
  53.         TEST    AL,AL        ; this code stops transfer on zero
  54.         JZ    @2        ; byte when encountered
  55.         ENDIF
  56.         LOOP    @1        ; loop till done
  57. @2:        MOV    AX,DI        ; Set the pointer up for exit
  58.         IF    @DataSize    ; Just an offset if small model
  59.         MOV    DX,ES        ; Segment part of address
  60.         ENDIF
  61.         POPF            ; Restore flags (Direction may have been altered?)
  62.         RET
  63. moveto        ENDP
  64.         END
  65. 
  66.